import 'package:bxultimate/app/router/router_name.dart';
import 'package:bxultimate/app/theme/app_theme.dart';
import 'package:bxultimate/app/theme/gaps.dart';
import 'package:bxultimate/resources/assets.dart';
import 'package:bxultimate/widgets/mk_card_container.dart';
import 'package:bxultimate/widgets/mk_list_cell_item.dart';
import 'package:bxultimate/widgets/mk_load_image.dart';
import 'package:bxultimate/widgets/mk_page.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

import 'controller.dart';

class SystemSettingIndexPage extends StatefulWidget {
  const SystemSettingIndexPage({Key? key}) : super(key: key);

  @override
  State<SystemSettingIndexPage> createState() => _SystemSettingIndexPageState();
}

class _SystemSettingIndexPageState extends State<SystemSettingIndexPage> {
  final controller = Get.find<SystemSettingIndexController>();
  final state = Get.find<SystemSettingIndexController>().state;

  @override
  Widget build(BuildContext context) {
    return MkPage(
        child: Scaffold(
            backgroundColor: Colors.transparent,
            appBar: TDNavBar(
              title: '设置',
              backgroundColor: Colors.transparent,
            ),
            body: ListView(
              children: <Widget>[
                _buildNav(),
                Gaps.vGap24,
                TDButton(
                  text: '退出登录',
                  isBlock: true,
                  theme: TDButtonTheme.primary,
                  onTap: controller.logout,
                )
              ],
            )));
  }

  _buildNav() {
    return MkCardContainer(
      padding: EdgeInsets.symmetric(horizontal: AppTheme.iDefaultPadding / 2),
      margin: EdgeInsets.symmetric(
          horizontal: AppTheme.iDefaultPadding,
          vertical: AppTheme.iDefaultPadding / 2),
      borderRadius: AppTheme.iBorderRadius,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          MkListCellItem(
            value: '账户与安全',
            textIcon: MkLoadImage(Assets.settingAq, width: 20),
            press: () {
              Get.toNamed(RouterName.userAccountIndex);
            },
          ),
          MkListCellItem(
            value: '隐私',
            textIcon: MkLoadImage(Assets.settingYs, width: 20),
            press: () => {
              Get.toNamed(RouterName.userPrivacyIndex)
            },
          ),
          MkListCellItem(
            value: '反馈与投诉',
            textIcon: MkLoadImage(Assets.settingFkts, width: 20),
            press: () => {Get.toNamed(RouterName.feedBack)},
          ),
          Obx(() => MkListCellItem(
                value: '关于',
                textIcon: MkLoadImage(Assets.settingAbout, width: 20),
                ext: Text(
                  '版本号 v${state.version}',
                  style: TextStyle(fontSize: 12, color: Colors.grey),
                ),
                press: () => {
                Get.toNamed(RouterName.appAbout)
                },
              )),
        ],
      ),
    );
  }

  @override
  void dispose() {
    Get.delete<SystemSettingIndexController>();
    super.dispose();
  }
}
